<?php

namespace App\Admin\Components;

use Dcat\Admin\Admin;
use Dcat\Admin\Support\Helper;
use Dcat\Admin\Widgets\Dropdown;

class SiteSelector
{
    public static function render($currentSiteId = 0)
    {
        // 获取所有站点（根据你的模型调整）
        $sites = \App\Models\Website::all();

        // 当前选中站点（从 session 获取）
        $currentSite = $sites->firstWhere('id', $currentSiteId);
        $currentName = $currentSite ? $currentSite->name : '选择站点';

        $options = [];
        foreach ($sites as $site) {
            $options[] = [
                'id'    => $site->id,
                'text'  => $site->name,
                'url'   => 'javascript:setCurrentSite('.$site->id.')',
                'active' => $site->id == $currentSite->id
            ];
        }

        // 没有站点时显示提示
        if (empty($options)) {
            return '<span class="text-danger">无可用站点</span>';
        }

        return view('admin.site-selector', [
            'current' => $currentName,
            'options' => $options
        ]);
    }
}